﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Xml;
using System.Data;

using Gift.DAL;
using Gift.Model;
using Gift.WebApp;


public partial class cn_UserControl_home_slides : System.Web.UI.UserControl
{
    // Fields


    protected string xmlPath = "/cn/xml/home.xml";
    readonly BasePage thePage = new BasePage();

    protected string moduleSetXmlPath = "/cn/xml/module_set.xml";

    // Methods
    protected StringBuilder HomeSlidesBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            XmlElement element;
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.xmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("home_ad/slides").ChildNodes;
            builder.AppendLine("<div class=\"banner_show\">");
            builder.AppendLine("<div class=\"slides\">");
            builder.AppendLine("<ul class=\"slide-pic\">");
            int num = 0;
            foreach (XmlNode node in childNodes)
            {
                element = (XmlElement)node;
                builder.AppendLine("<li " + ((num == 0) ? "class=\"cur\"" : "") + " >");
                builder.AppendLine("<a href=\"" + element.GetAttribute("url") + "\" target=\"_blank\"><img src=\"" + element.GetAttribute("src") + "\" alt=\"" + element.GetAttribute("alt") + "\" /></a>");
                builder.AppendLine("</li>");
                num++;
            }
            builder.AppendLine("</ul>");
            builder.AppendLine("<ul class=\"slide-li slide-txt op\">");
            num = 0;
            foreach (XmlNode node in childNodes)
            {
                element = (XmlElement)node;
                builder.AppendLine("<li " + ((num == 4) ? "class=\"last\"" : "") + "><a href=\"" + element.GetAttribute("url") + "\" target=\"_blank\">" + element.GetAttribute("alt") + "</a></li>");
            }
            builder.AppendLine("</ul>");
            builder.AppendLine("</div>");
            XmlElement element2 = (XmlElement)document.SelectSingleNode("home_ad/slides_bottom");
            if (element2 != null)
            {
                builder.AppendLine("<div class=\"banner_img\">");
                builder.AppendLine("<a href=\"" + element2.GetAttribute("url") + "\" target=\"_blank\"><img src=\"" + element2.GetAttribute("src") + "\" alt=\"" + element2.GetAttribute("alt") + "\" /></a>");
                builder.AppendLine("</div>");
            }
            builder.AppendLine("</div>");
            builder.AppendLine("<div class=\"news_info\">");
            builder.AppendLine("<div class=\"content-box\">");
            builder.AppendLine("<div class=\"content-box-header\">");
            builder.AppendLine("<ul class=\"content-box-tabs\">");
            builder.AppendLine("<li><a href=\"#tab1\" class=\"default-tab\">资讯中心</a></li>");
            builder.AppendLine("<li><a href=\"#tab2\">积分回馈</a></li>");
            builder.AppendLine("</ul>");
            builder.AppendLine("</div>");
            builder.AppendLine("<div class=\"content-box-content\">");
            builder.AppendLine("<div class=\"tab-content default-tab\" id=\"tab1\">");
            builder.AppendLine("<ul>");
            DataTable atricleByArticleTypeIdAndTop = BaseFactory.theArticle.GetAtricleByArticleTypeIdAndTop(BaseFactory.theArticleType.GetIdByTypeNameAndParentIdAndIsShow("资讯中心", "00000000-0000-0000-0000-000000000000", 1), 4);
            foreach (DataRow row in atricleByArticleTypeIdAndTop.Rows)
            {
                builder.AppendLine(string.Concat(new object[] { "<li><a href=\"/cn/news_center/news_detail.html?id=", row["id"], "\" title=\"", row["articleTilte"], "\">- ", (row["articleTilte"].ToString().Length > 12) ? (row["articleTilte"].ToString().Substring(0, 12) + "..") : row["articleTilte"], "</a></li>" }));
            }
            builder.AppendLine("</ul>");
            builder.AppendLine("</div>");
            builder.AppendLine("<div class=\"tab-content\" id=\"tab2\">");
            builder.AppendLine("<ul>");
            DataTable table2 = BaseFactory.theArticle.GetAtricleByArticleTypeIdAndTop(BaseFactory.theArticleType.GetIdByTypeNameAndParentIdAndIsShow("积分回馈", "00000000-0000-0000-0000-000000000000", 1), 4);
            foreach (DataRow row in table2.Rows)
            {
                builder.AppendLine(string.Concat(new object[] { "<li><a href=\"#\" title=\"", row["articleTilte"], "\">- ", (row["articleTilte"].ToString().Length > 12) ? (row["articleTilte"].ToString().Substring(0, 12) + "..") : row["articleTilte"], "</a></li>" }));
            }
            builder.AppendLine("</ul>");
            builder.AppendLine("</div>");
            builder.AppendLine("</div>");
            builder.AppendLine("</div>");
            builder.AppendLine("<div class=\"img_link\">");
            XmlNodeList list2 = document.SelectSingleNode("home_ad/slides_right").ChildNodes;
            foreach (XmlNode node in list2)
            {
                element = (XmlElement)node;
                builder.AppendLine("<a href=\"" + element.GetAttribute("url") + "\" target=\"_blank\" title=\"" + element.GetAttribute("alt")  + "\" ><img src=\"" + element.GetAttribute("src") + "\" alt=\"" + element.GetAttribute("alt") + "\" /></a>");
            }
            builder.AppendLine("</div>");
            builder.AppendLine("</div>");
        }
        catch
        {
        }
        return builder;
    }



    protected StringBuilder MenuNavigationBind()
    {
        StringBuilder builder = new StringBuilder();
        try
        {
            DataTable table3;
            DataTable brandByCategoryIdentity;
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.moduleSetXmlPath));
            XmlElement element = document.SelectSingleNode("set/navigation_brand") as XmlElement;
            DataTable table = BaseFactory.theCategory.GetCategoryByParentIdAndCompanyIdAndIsShow("00000000-0000-0000-0000-000000000000", thePage.CompanyId, 1);


            builder.Append("<div id='leftMenu'>");
            int num = 1;
            foreach (DataRow row in table.Rows)
            {
                builder.AppendLine("<div class=\"cate_item\">");
                builder.AppendLine("<div class=\"cate_title\">");
                builder.AppendLine(string.Concat(new object[] { "<h3><strong><a href=\"/cn/goods_list.html?cid=", row["id"], "\">", row["categoryName"], "</a></strong></h3>" }));
                builder.AppendLine("<em></em>");
                builder.AppendLine("</div>");
                builder.AppendLine("<div class=\"citem top_" + num + "\">");
                builder.AppendLine("<div class=\"citem_left\">");
                builder.AppendLine("<div class=\"all_cate_tit\">全部分类</div>");
                builder.AppendLine("<dl>");
                table3 = BaseFactory.theCategory.GetCategoryByParentIdAndCompanyIdAndIsShow(row["id"].ToString(), thePage.CompanyId, 1);
                foreach (DataRow row2 in table3.Rows)
                {
                    builder.AppendLine(string.Concat(new object[] { "<dt><a href=\"goods_list.html?cid=", row2["categoryIdentity"], "\">", row2["categoryName"], "</a> </dt>" }));
                    DataTable table4 = BaseFactory.theCategory.GetCategoryByParentIdAndCompanyIdAndIsShow(row2["id"].ToString(), thePage.CompanyId, 1);
                    foreach (DataRow row3 in table4.Rows)
                    {
                        builder.AppendLine(string.Concat(new object[] { "<dd><a href=\"/cn/goods_list.html?cid=", row3["categoryIdentity"], "\">", row3["categoryName"], "</a></dd>" }));
                    }
                }
                builder.AppendLine("</dl>");
                builder.AppendLine("</div>");
                if (element.GetAttribute("isShow") == "true")
                {
                    builder.AppendLine("<div class=\"citem_right\">");
                    builder.AppendLine("<dl class=\"brands\">");
                    builder.AppendLine("<dt>" + element.GetAttribute("title") + "</dt>");
                    builder.AppendLine("<dd>");
                    brandByCategoryIdentity = BaseFactory.theBrand.GetBrandByCategoryIdentity(Convert.ToInt32(row["categoryIdentity"]));
                    foreach (DataRow row4 in brandByCategoryIdentity.Rows)
                    {
                        builder.AppendLine(string.Concat(new object[] { "<em><a href=\"/cn/goods_list.html?cid=", row["categoryIdentity"], "&bid=", row4["id"], "\">", row4["brandName"], "</a></em>" }));
                    }
                    builder.AppendLine("</dd>");
                    builder.AppendLine("</dl>");
                    builder.AppendLine("</div>");
                }
                builder.AppendLine("<span class=\"clear\"></span>");
                builder.AppendLine("</div>");
                builder.AppendLine("</div>");
                num++;
            }
            builder.AppendLine("<div class=\"allcate\"><a href=\"/cn/goods_list.html\">全部商品分类</a></div>");
            builder.Append("</div>");
        
        }
        catch
        {
        }
        return builder;
    }


    protected void Page_Load(object sender, EventArgs e)
    {
    }

}